import java.util.Scanner;

/**
 * @author gao
 * @date 2025/11/12 17:02
 */

public class Solution {
    public int minOperations(int[] nums, int x) {
        int len = nums.length, sum = 0, ret = -1;
        for (int i : nums) {
            sum += i;
        }
        int target = sum - x;

        if (target < 0) {
            return -1;
        }

        for (int left = 0, right = 0, tmp = 0; right < len; right++) {
            tmp += nums[right];

            while (tmp > target) {
                tmp -= nums[left];
                left++;
            }

            if (tmp == target) {
                ret = Math.max(ret, right - left + 1);
            }
        }

        if (ret == -1) {
            return ret;
        } else {
            return len - ret;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();
            }
            int x = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.minOperations(nums, x));
        }
    }
}